<?php

namespace app\common;

use think\facade\Db;
use think\facade\Request;

class Log
{
    public static function write($event, $id, $tag = 1, $remark = ''): bool
    {
        $route = Request::route();
        // 获取当前请求的完整 URL
        $url = Request::url();
        $data = array(
            'tag' => $tag,
            'time' => date('Y-m-d H:i:s'),
            'event' => $event,
            'account' => $id,
            'url' => $url,
            'remark' => $remark
        );
//    print_r($data);
        try {
            $OResult = Db::name('log')->insert($data);
            if ($OResult == 1) {
                return true;
            } else {
                return false;
            }
        } catch (\Exception $e) {
            return false;
        }
    }
}